package cn.zcy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {
    /**
     * RequestMapping 将方法映射给url处理
     * @param name  springmvc 参数自动匹配
     * @return
     */
    @GetMapping("/params01")
//    @ResponseBody
    public String hello(@RequestParam(name = "username",required = false) String name){
        System.out.println("hello " +name);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("success");
        modelAndView.addObject("hello","springmvc");
        // 响应
        // redirect 重定向 地址值发生变换
        // forward 转发 默认 地址值不变

        return "success";
    }
}
